package com.fuint.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.service.MerchantService;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.mapper.MtGoodsMapper;
import com.fuint.repository.mapper.MtMerchantMapper;
import com.fuint.repository.mapper.MtStoreMapper;
import com.fuint.repository.model.MtMerchant;
import com.fuint.utils.StringUtil;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 商户业务实现类
 *
 * Created by FSQ
 * CopyRight https://www.fuint.cn
 */
@Service
@AllArgsConstructor
public class MerchantServiceImpl extends ServiceImpl<MtMerchantMapper, MtMerchant> implements MerchantService {

    private MtMerchantMapper mtMerchantMapper;

    private MtStoreMapper mtStoreMapper;

    private MtGoodsMapper mtGoodsMapper;

    private static final Logger logger = LoggerFactory.getLogger(MerchantServiceImpl.class);


    @Override
    public PaginationResponse<MtMerchant> queryMerchantListByPagination(PaginationRequest paginationRequest) throws BusinessCheckException {
        return null;
    }

    @Override
    public MtMerchant saveMerchant(MtMerchant mtMerchant) throws BusinessCheckException {
        return null;
    }

    @Override
    public MtMerchant queryMerchantById(Integer id) throws BusinessCheckException {
        return null;
    }

    @Override
    public MtMerchant queryMerchantByName(String name) throws BusinessCheckException {
        return null;
    }

    /**
     * 根据商户号获取商户信息
     *
     * @param merchantNo 商户号
     * @return
     */
    @Override
    public MtMerchant queryMerchantByNo(String merchantNo) {
        return mtMerchantMapper.queryMerchantByNo(merchantNo);
    }

    /**
     * 根据商户号获取商户ID
     *
     * @param merchantNo 商户号
     * @return
     */
    @Override
    public Integer getMerchantId(String merchantNo) {
        //如果传来的商户号是null或者空字符串，就返回商户Id为0
        if (merchantNo==null|| StringUtil.isEmpty(merchantNo)){
            return 0;
        }
        //否则，根据商户号查询商户信息，并返回商户ID
        MtMerchant mtMerchant = queryMerchantByNo(merchantNo);
        if (mtMerchant!=null){
            return mtMerchant.getId();
        }

        return 0;
    }

    @Override
    public void updateStatus(Integer id, String operator, String status) throws BusinessCheckException {

    }

    @Override
    public List<MtMerchant> queryMerchantByParams(Map<String, Object> params) throws BusinessCheckException {
        return Collections.emptyList();
    }
}
